package com.grape.juc.thread.join;

/**
 * 描述:join()方法应用
 * @author: myx
 * @date: 2019-05-05
 * Copyright © 2019-grape. All rights reserved.
 */
public class JoinTest {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = getOneThread("t1");
        Thread t2= getOneThread("t2");
        Thread t3= getOneThread("t3");
        t1.start();
        //阻断main线程执行优先执行t1
        t1.join();
        t2.start();
        t2.join();
        t3.start();

    }


    /**
     * 获取一个新的线程
     * @param name  线程名称
     * @return
     */
    public static Thread getOneThread(String name){
        return new Thread(()->{
            for (int i = 0; i < 10; i++) {
                try {
                    Thread.sleep(10);
                } catch (Exception e) {

                }
                System.out.println(Thread.currentThread().getName() + "i:" + i);
            }
        },name);
    }
}
